import React, { Component } from 'react'
import { ListBox } from '../../../components'
import UpdateWorkareaPage from './UpdateNew'
import UpdateWorkareaPageUp from './UpdateNewUp'
import ContractNumberForm from './ContractNumberForm'
import { fetchData } from '../../../components/AjaxConsumer'
import { Button, Modal, Form, Input, Radio, Upload, Icon } from 'antd';
export default class ListProStroageSnPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
            // {
            //     handleName: 'edit',
            //     iconClass: 'cellEdit'
            // }, {
            //     handleName: 'delete',
            //     iconClass: 'cellDele'
            // }, {
            //     handleName: 'assignUser',
            //     iconClass: 'cellRole'
            // }
        ];
        //header 操作列表
        this.headerOperation = [
            // {
            //     handleName: 'edit',
            //     showName: '合同号修改',
            //     iconClass: 'edit',
            //     permission: 'procontract-edit'
            // }
            // {
            //     handleName: 'addWorkarea',
            //     showName: '新增',
            //     iconClass: 'plus',
            //     permission: 'rawunit-add'
            // }, {
            //     handleName: 'edit',
            //     showName: '修改',
            //     iconClass: 'edit',
            //     permission: 'rawunit-edit'
            // }
            // , {
            //     handleName: 'delete',
            //     showName: '删除',
            //     iconClass: 'delete',
            //     permission: 'rawunit-del'
            // }, {
            //     handleName: 'upload',
            //     showName: '上传',
            //     iconClass: 'upload',
            //     permission: 'rawunit-upload'
            // }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'listProStroagePageSn',
            data: [
                {
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth:120
                },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth:120
                }, {
                    showName: '品名',
                    columnName: 'productName',
                    columnWidth:120
                }, {
                    showName: '定量',
                    columnName: 'density',
                },{
                    showName: '重量',
                    columnName: 'weight',
                },{
                    showName: '单位',
                    columnName: 'unit'
                },{
                    showName: '规格',
                    columnName: 'spec',
                    
                },{
                    showName: '类型',
                    columnName: 'type',
                    showOption: [//页面显示配置
                        {
                            optionKey: '0',
                            optionShow: '正品'
                        }, {
                            optionKey: '1',
                            optionShow: '样品'
                        }
                    ]
                }, {
                    showName: '生产机号',
                    columnName: 'machineNumber',
                    showOption:[
                        {
                            optionKey: 2,
                            optionShow:'2号机'
                        },{
                            optionKey: 4,
                            optionShow:'4号机'
                        }
                    ]
                },{
                    showName: '等级',
                    columnName: 'grade',
                    showOption: [//页面显示配置
                        {
                            optionKey: '1',
                            optionShow: '一等品'
                        }, {
                            optionKey: '2',
                            optionShow: '二等品'
                        }, {
                            optionKey: '3',
                            optionShow: '处理品'
                        }
                    ]
                },{
                    showName: '级别',
                    columnName: 'level',
                },{
                    showName: '排产时间',
                    columnName: 'proPlanDate',
                    columnWidth:160
                },{
                    showName: '生产时间',
                    columnName: 'proManuDate',
                    columnWidth:160
                },
                //{
                //    showName: '单位',
                //    columnName: 'unit'
                //},
                // {
                //     showName: '仓库',
                //     columnName: 'whCode'
                // }, {
                //     showName: '区域',
                //     columnName: 'wdCode'
                // }, {
                //     showName: '库区',
                //     columnName: 'waCode'
                // },
                 {
                    showName: '仓库',
                    columnName: 'wlCode'
                },{
                    showName: '状态',
                    columnName: 'barcodeStatus',
                    showOption: [
                        {
                            optionKey: '0',
                            optionShow: '可用'
                        },
                         {
                            optionKey: '1',
                            optionShow: '冻结'
                        }, {
                            optionKey: '2',
                            optionShow: '已出库'
                        }, {
                            optionKey: '3',
                            optionShow: '抽检冻结'
                        }
                    ]
                },
                // {
                //     showName: '出库方式',
                //     columnName: 'userDefined1',
                //     showOption: [//页面显示配置
                //         {
                //             optionKey: '0',
                //             optionShow: '正常出库'
                //         }, {
                //             optionKey: '1',
                //             optionShow: '报废出库'
                //         }
                //     ]
                // },
                {
                    showName: '创建人',
                    columnName: 'createBy'
                },{
                    showName: '创建时间',
                    columnName: 'gmtCreate',
                    columnWidth:160
                },{
                    showName: '最后修改人',
                    columnName: 'lastModifiedBy'
                },{
                    showName: '最后修改时间',
                    columnName: 'gmtModified',
                    columnWidth:160
                },
                // {
                //     showName: '激活标记',
                //     columnName: 'activeFlag'
                // }
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList: [
                   
                ]
            }, {
                showName: '状态',
                name: 'barcodeStatus',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    }, {
                        optionKey: '0',
                        optionShow: '可用'
                    }, {
                        optionKey: '1',
                        optionShow: '冻结'
                    }, {
                        optionKey: '2',
                        optionShow: '已出库'
                    }, {
                        optionKey: '3',
                        optionShow: '报废'
                    }
                ]
            },{
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    }, {
                        optionKey: '1',
                        optionShow: '一等品'
                    }, {
                        optionKey: '2',
                        optionShow: '二等品'
                    }, {
                        optionKey: '3',
                        optionShow: '处理品'
                    }
                ]
            },{
                showName: '冻结原因',
                name: 'lockReason',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },
                     {
                        optionKey: '2',
                        optionShow: '质量冻结'
                    }, {
                        optionKey: '4',
                        optionShow: '手工冻结'
                    }
                ]
            },{
                name:'proPlanDate',
                type: 'date',
                maxName:'proPlanDateMax',
                minName:'proPlanDateMin',
            },{
                name:'proManuDate',
                type: 'date',
                maxName:'proManuDateMax',
                minName:'proManuDateMin',
            },{
                name:'gmtModified',
                type: 'date',
                maxName:'gmtModifiedMax',
                minName:'gmtModifiedMin',
            },{
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin',
                columnWidth:150
            },{
                showName: '产品类型',
                name: 'type',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },
                     {
                        optionKey: '0',
                        optionShow: '正品'
                    }, {
                        optionKey: '1',
                        optionShow: '样品'
                    }
                ]
            },{
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList: [
                    {
                        optionKey: '',
                        optionShow: ''
                    },
                     {
                        optionKey: 'A',
                        optionShow: 'A'
                    }, {
                        optionKey: 'B',
                        optionShow: 'B'
                    }, {
                        optionKey: 'C',
                        optionShow: 'C'
                    }
                ]
            },
            {
                showName: '仓库',
                name: 'wlCode',
                type: 'select',
                url: '/base/data/location/get/wl_code'
            },
            {
                showName: '单位',
                name: 'unit',
                type: 'select',
                url: '/base/dic/get/unit'
            },{
                name:'weight',
                type: 'number',
                maxName:'weightMax',
                minName:'weightMin'
            },
            {
                showName: '生产机号',
                name:'machineNumber',
                type: 'select',
                // optionList:[]
                url:'/base/dic/get/machine_number'
            }
            
        ];

    }


    // componentWillMount() {
    //     const dicType = 'model_type_p';
    //     const options= {
    //         url: '/base/dic/get/' + dicType,
    //         type: 'get',
    //         condition:{}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options, this.dicInitCallBackHandle);
    // }

    // //下拉框 初始化
    // dicInitCallBackHandle = (resData)=>{
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });
    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[5].showOption = optionList;
    //     this.searchComponentData[0].optionList = optionList;
    // }

    rowHandles = (strHandles, rowObj) => {
        // console.log("strHandles===ListResource=======", strHandles);
        // if (strHandles === 'edit') {
        //     this.editHandle(rowObj);
        // } else if (strHandles === 'delete') {
        //     this.deleteHandle(rowObj);
        // } else if (strHandles === 'addWorkarea') {
        //     this.addWorkareaHandle();
        // } else if (strHandles == 'assignUser') {
        //     this.assignFactoryUserHandle(rowObj);
        // } else if (strHandles == 'upload') {
        //     this.upload();
        // }
        if (strHandles === 'edit') {
            this.editHandle(rowObj);
        }
    }
    // 增加工作区
    addWorkareaHandle = () => {
        console.log("====执行了新增工作区操作====");
        this.refs.updateWorkarea.addWorkareaHandle();
    }

    // 上传
    upload = () => {
        console.log("====执行了上传操作====");
        //    this.setState({ visible: true });
        this.refs.updateWorkareaUp.add();



    }
    // editHandle = (rowObj) => {
    //     if (rowObj.length == 0) {
    //         Modal.error({
    //             title: '错误提示',
    //             content: '请选择一条数据',
    //         });
    //     } else if (rowObj.length > 1) {
    //         Modal.error({
    //             title: '错误提示',
    //             content: '只能选择一条数据',
    //         });
    //     } else {
    //         this.refs.updateWorkarea.editHandle(rowObj[0].data);
    //     }
    // }

    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else {
            //this.refs.updateDock.editHandle(rowObj[0].data);

            let id = rowObj[0].data.storageSnId;

            let options={
                url: '/product/insidewarehouse/findById/' + id,
                type: 'get',//请求方式
                condition: {id: id}

                // url: '/material/insidewarehouse/RawStorageSn/get/' + id,
                // type: 'get',//请求方式
                // condition: {id: id}
            };

            fetchData(this, options, (resData) => {
                if (resData.code == '1'){
                    this.setState({
                        formData:resData.data,
                        submitUrl:'/product/insidewarehouse/updateById'
                        // submitUrl: '/material/insidewarehouse/RawStorageSn/out/edit',
                    });
                    this.showModal();
                }else {
                    message.error(resData.msg);
                }
            });
        }

    }

    deleteHandle = (rowObj) => {
        if (rowObj.length == 0) {
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        } else if (rowObj.length > 1) {
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        } else {
            this.refs.updateWorkarea.deleteHandle(rowObj[0].data)
        }
    }
    // 给区域分配角色
    assignFactoryUserHandle = (rowObj) => {
        let workareaId = rowObj.workareaId;
        this.refs.assignFactoryUser.initModal(workareaId);
    }


    //刷新列表
    refreshHandle = () => {
        this.refs.listWorkarea.refreshHandle();
    }

    showModal = () => {
        this.setState({
            visible: true
        });
    }

    handleCancel = () => {
        this.setState({
            visible: false
        });
    }
    

    // handleCancel = () => {
    //     this.setState({ visible: false });
    //     this.form.resetFields();

    // }
    handleCreate = () => {
        const form = this.form;
        form.validateFields((err, values) => {
            if (err) {
                return;
            }

            console.log('Received values of form: ', values);
            form.resetFields();
            this.setState({ visible: false });
        });
    }
    saveFormRef = (form) => {
        this.form = form;
    }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listWorkarea'
                    title="成品库存明细"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/product/insidewarehouse/storagesn/list'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle="true"
                />

                                <Modal
                    style={{top: '20px'}}
                    visible={this.state.visible}
                    title="物料转换"
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                    width={'850px'}
                    footer=''
                    maskClosable={false}>
                    <ContractNumberForm
                        onCancel={this.handleCancel}
                        ref="ContractNumberForm"
                        submitUrl={this.state.submitUrl}
                        formData={this.state.formData}
                        init={this.state.visible}
                        refreshHandle={this.refreshHandle}
                    />
                </Modal>

                <UpdateWorkareaPage
                    ref="updateWorkarea"
                    refreshHandle={this.refreshHandle}
                />
                <UpdateWorkareaPageUp
                    ref="updateWorkareaUp"
                    refreshHandle={this.refreshHandle}
                />

            </div>
        )
    }
}
